package com.jzr.board.presenter.impl

import android.content.Context
import com.jzr.board.api.Api
import com.jzr.board.base.BasePresenter
import com.jzr.board.bean.BoardGetBean
import com.jzr.board.bean.ConnectTestBean
import com.jzr.board.presenter.contract.TodyWorkFragmentContract
import rx.Observer
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers

class TodyWorkFragmentImpl : BasePresenter<TodyWorkFragmentContract.View>(),
    TodyWorkFragmentContract.Presenter<TodyWorkFragmentContract.View> {



    override fun getBoardGet(context: Context?, vararg s: String?) {
        showLoadingDialog(context)
        addSubscrebe(
            Api.getInstance()?.getBoardGet(*s)
                ?.observeOn(AndroidSchedulers.mainThread())
                ?.subscribeOn(Schedulers.io())
                ?.unsubscribeOn(Schedulers.io())
                ?.subscribe(object : Observer<BoardGetBean?> {
                    override fun onCompleted() {}
                    override fun onError(e: Throwable) {
                        dismissLoadingDialog()
                        if (mView != null) mView?.showError("连接失败")
                    }

                    override fun onNext(t: BoardGetBean?) {
                        dismissLoadingDialog()
                        if (mView != null && t != null && t.code ==0) {
                            mView?.getBoardGetSuccess(t)
                        } else {
                            mView?.showError("连接失败")
                        }
                    }
                })
        )
    }
}